const Service = require('egg').Service

class AuditService extends Service {
	constructor(ctx) {
		super(ctx)
	}
	async index(params) {
		let { pageSize = 10, pageNum = 1 } = params
		pageSize = Number(pageSize)
		const offset = (pageNum - 1) * pageSize
		const data = await this.ctx.model.Article.findAndCountAll({
			include: [
				{
					model: this.ctx.model.User,
					attributes: ['username'],
				},
				{
					model: this.ctx.model.Tag,
					attributes: ['tagName'],
				},
			],
			where: {
				status: [1, 2, 3],
			},
			limit: pageSize,
			offset,
			distinct: true,
		})
		return data
	}
	async update(id, body) {
		const { status } = body
        let _status = 0
		if (status) {
			_status = 2
		} else {
			_status = 3
		}
		await this.ctx.model.Article.update(
			{ status:_status },
			{
				where: { id },
			}
		)
		return 'success'
	}
}

module.exports = AuditService
